package com.ls.blog.utils;

/**
 * @program: graduationDesign
 * @author: lishun
 * @create: 2021-10-01 12:51
 **/
import org.springframework.beans.BeanUtils;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 对象工具
 */
public class ObjectUtils {


    /**
     * 对象拷贝
     * @param <T>
     * @param resource
     * @param target
     * @return
     * @throws IllegalAccessException
     * @throws InstantiationException
     */
    public static <T> T  copyObject(Object resource, Class<T> target)  {
        T t = null;
        try {
            t = target.newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        BeanUtils.copyProperties(resource,t);
        return t;
    }

    public static <T> List<T> copyList(List list,Class<T> target){
        return (List<T>) list.stream()
                .map(item->copyObject(item,target)
        ).collect(Collectors.toList());
    }

    public static void main(String[] args) {
        int a = 1;
    }
}
